<style>
    .layui-upload-img {
        width: 92px;
        height: 92px;
        margin: 0 10px 10px 0;
        background-color: #eee;
    }
</style>
<div class="layui-form-item">
    <label class="layui-form-label">图标</label>
    <div class="layui-input-block upload-icon">
        <input type="hidden" name="icon">
        <div class="layui-upload">
            <button type="button" class="layui-btn" id="upload-icon">上传图片</button>
            <div class="layui-upload-list">
                <img class="layui-upload-img" id="upload-icon-demo"  style="display: none">
                <p id="demoText"></p>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['upload',"okLayer"], function(){
        var $ = layui.jquery
            ,okLayer = layui.okLayer
            ,upload = layui.upload;

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#upload-icon'
            ,url: "{:addons_url('store://Upload/uploadIcon')}" //改成您自己的上传接口
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#upload-icon-demo').attr('src', result).css('display','block'); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.status !== 200){
                    return layer.msg('上传失败');
                }
                $('.upload-icon input[name="icon"]').val(res.data)
                okLayer.greenTickMsg(res.msg, function () {})
                //上传成功
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });
    })
</script>
{if !empty($data) }
{if !empty($data) && empty($data.icon)}
<script>let show2 = 'none'</script>
{else /}
<script>let show2 = 'block'</script>
{/if}
<script>
    layui.use('jquery',function () {
        let $ = layui.jquery;
        $('.upload-icon input[name="icon"]').val('{$data.icon}')
        $('#upload-icon-demo').attr('src', '{$data.icon|default=""}').css('display',show2)
    })
</script>
{else /}
<script>
    var checkedId = null
</script>
{/if}